﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyDemoWebSite.Controllers.Base;
using Models.Models;
using Bll.Demo;



namespace MyDemoWebSite.Controllers.Demo
{
    /// <summary>
    /// Demo User操作
    /// </summary>
    public class UserController :BaseController
    {
        //
        // GET: /User/

        public ActionResult Index()
        {
            //BaseController变量
            ViewBag.CreateUser = CreateUser;
            //获取全部
            UserBll userBll = new UserBll();
            List<User> lstUser=userBll.GetAll();
            return View(lstUser);
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        public ActionResult Add()
        {
            User model = new User();
            return View(model);
        }
        [HttpPost]
        public ActionResult Add(User model)
        {
            UpdateModel(model);
            UserBll userBll = new UserBll();
            string Id=userBll.Add(model);//返回主键
            return RedirectToAction("Index");
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public ActionResult Edit(string Id)
        {
            UserBll userBll = new UserBll();
            User model=userBll.Get(Id);
            return View(model);
        }

        [HttpPost]
        public ActionResult Edit(User model)
        {
            UpdateModel(model);
            UserBll userBll = new UserBll();
            userBll.Update(model);
            return RedirectToAction("Index");
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public ActionResult Delete(string Id)
        {
            UserBll userBll = new UserBll();
            userBll.Delete(Id);
            return RedirectToAction("Index");
        }

    }
}
